home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / DSTACK.H < prev    next >
C/C++ Source or Header  |  1992-02-10  |  7KB  |  188 lines

  1. /* Copyright (C) 1990-92 Free Software Foundation, Inc.
  2.  
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 1, or (at your option)
  6.    any later version.
  7.  
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17. /* $Header: /scheme/src/microcode/RCS/dstack.h,v 1.5 1992/02/10 13:09:11 jinx Exp $ */
  18.  
  19. #ifndef __DSTACK_H__
  20. #define __DSTACK_H__
  21.  
  22. #include "ansidecl.h"
  23. #include <setjmp.h>
  24.  
  25. extern void
  26.   EXFUN (abort, (void)),
  27.   EXFUN (exit, (int)),
  28.   EXFUN (free, (void *));
  29.  
  30. extern void EXFUN (dstack_initialize, (void));
  31. /* Call this once to initialize the stack. */
  32.  
  33. extern void EXFUN (dstack_reset, (void));
  34. /* Call this once to reset the stack. */
  35.  
  36. extern PTR EXFUN (dstack_alloc, (unsigned int length));
  37. /* Allocate a chunk of `length' bytes of space on the stack and return
  38.    a pointer to it. */
  39.  
  40. extern void EXFUN
  41.   (dstack_protect,
  42.    (void EXFUN ((*protector), (PTR environment)), PTR environment));
  43. /* Create an unwind protection frame that invokes `protector' when
  44.    the stack is unwound.  `environment' is passed to `protector' as
  45.    its sole argument when it is invoked. */
  46.  
  47. extern void EXFUN
  48.   (dstack_alloc_and_protect,
  49.    (unsigned int length,
  50.     void EXFUN ((*initializer), (PTR environment)),
  51.     void EXFUN ((*protector), (PTR environment))));
  52. /* Allocate a chunk of `length' bytes of space, call `initializer' to
  53.    initialize that space, and create an unwind protection frame that
  54.    invokes `protector' when the stack is unwound.  */
  55.  
  56. extern PTR dstack_position;
  57. /* The current stack pointer. */
  58.  
  59. extern void EXFUN (dstack_set_position, (PTR position));
  60. /* Unwind the stack to `position', which must be a previous value of
  61.    `dstack_position'. */
  62.  
  63. extern void EXFUN (dstack_bind, (PTR location, PTR value));
  64. /* Dynamically bind `location' to `value'.  `location' is treated as
  65.    `PTR*' -- it is declared `PTR' for programming convenience. */
  66.  
  67. enum transaction_action_type { tat_abort, tat_commit, tat_always };
  68.  
  69. extern void EXFUN (transaction_initialize, (void));
  70. extern void EXFUN (transaction_begin, (void));
  71. extern void EXFUN (transaction_abort, (void));
  72. extern void EXFUN (transaction_commit, (void));
  73. extern void EXFUN
  74.   (transaction_record_action,
  75.    (enum transaction_action_type type,
  76.     void EXFUN ((*procedure), (PTR environment)),
  77.     PTR environment));
  78.  
  79. typedef unsigned long Tptrvec_index;
  80. typedef unsigned long Tptrvec_length;
  81.  
  82. struct struct_ptrvec
  83. {
  84.   Tptrvec_length length;
  85.   PTR * elements;
  86. };
  87. typedef struct struct_ptrvec * Tptrvec;
  88.  
  89. #define PTRVEC_LENGTH(ptrvec) ((ptrvec) -> length)
  90. #define PTRVEC_REF(ptrvec, index) (((ptrvec) -> elements) [(index)])
  91. #define PTRVEC_LOC(ptrvec, index) (& (PTRVEC_REF ((ptrvec), (index))))
  92. #define PTRVEC_START(ptrvec) (PTRVEC_LOC ((ptrvec), 0))
  93. #define PTRVEC_END(ptrvec) (PTRVEC_LOC ((ptrvec), (PTRVEC_LENGTH (ptrvec))))
  94.  
  95. extern Tptrvec EXFUN (ptrvec_allocate, (Tptrvec_length length));
  96. extern void EXFUN (ptrvec_deallocate, (Tptrvec ptrvec));
  97. extern void EXFUN (ptrvec_set_length, (Tptrvec ptrvec, Tptrvec_length length));
  98. extern Tptrvec EXFUN (ptrvec_copy, (Tptrvec ptrvec));
  99. extern void EXFUN (ptrvec_adjoin, (Tptrvec ptrvec, PTR element));
  100. extern int EXFUN (ptrvec_memq, (Tptrvec ptrvec, PTR element));
  101. extern void EXFUN
  102.   (ptrvec_move_left,
  103.    (Tptrvec source, Tptrvec_index source_start, Tptrvec_index source_end,
  104.     Tptrvec target, Tptrvec_index target_start));
  105. extern void EXFUN
  106.   (ptrvec_move_right,
  107.    (Tptrvec source, Tptrvec_index source_start, Tptrvec_index source_end,
  108.     Tptrvec target, Tptrvec_index target_start));
  109.  
  110. typedef struct condition_type * Tcondition_type;
  111. typedef struct condition * Tcondition;
  112. typedef struct condition_restart * Tcondition_restart;
  113.  
  114. struct condition_type
  115. {
  116.   unsigned long index;
  117.   PTR name;
  118.   Tptrvec generalizations;
  119.   void EXFUN ((*reporter), (Tcondition));
  120. };
  121. #define CONDITION_TYPE_INDEX(type) ((type) -> index)
  122. #define CONDITION_TYPE_NAME(type) ((type) -> name)
  123. #define CONDITION_TYPE_GENERALIZATIONS(type) ((type) -> generalizations)
  124. #define CONDITION_TYPE_REPORTER(type) ((type) -> reporter)
  125.  
  126. struct condition
  127. {
  128.   Tcondition_type type;
  129.   Tptrvec irritants;
  130. };
  131. #define CONDITION_TYPE(condition) ((condition) -> type)
  132. #define CONDITION_IRRITANTS(condition) ((condition) -> irritants)
  133.  
  134. struct condition_restart
  135. {
  136.   PTR name;
  137.   Tcondition_type type;
  138.   void EXFUN ((*procedure), (PTR));
  139. };
  140. #define CONDITION_RESTART_NAME(restart) ((restart) -> name)
  141. #define CONDITION_RESTART_TYPE(restart) ((restart) -> type)
  142. #define CONDITION_RESTART_PROCEDURE(restart) ((restart) -> procedure)
  143.  
  144. /* Allocate and return a new condition type object. */
  145. extern Tcondition_type EXFUN
  146.   (condition_type_allocate,
  147.    (PTR name,
  148.     Tptrvec generalizations,
  149.     void EXFUN ((*reporter), (Tcondition condition))));
  150.  
  151. /* Deallocate the condition type object `type'. */
  152. extern void EXFUN (condition_type_deallocate, (Tcondition_type type));
  153.  
  154. /* Allocate and return a new condition object. */
  155. extern Tcondition EXFUN
  156.   (condition_allocate, (Tcondition_type type, Tptrvec irritants));
  157.  
  158. /* Deallocate the condition object `condition'. */
  159. extern void EXFUN (condition_deallocate, (Tcondition condition));
  160.  
  161. /* Bind a handler for the condition type object `type'. */
  162. extern void EXFUN
  163.   (condition_handler_bind,
  164.    (Tcondition_type type, void EXFUN ((*handler), (Tcondition condition))));
  165.  
  166. /* Signal `condition'. */
  167. extern void EXFUN (condition_signal, (Tcondition condition));
  168.  
  169. /* Bind a restart called `name' for the condition type object `type'.
  170.    Invoking the restart causes `restart_procedure' to be executed. */
  171. extern void EXFUN
  172.   (condition_restart_bind,
  173.    (PTR name,
  174.     Tcondition_type type,
  175.     void EXFUN ((*procedure), (PTR argument))));
  176.  
  177. /* Find a restart called `name' that matches `condition'.
  178.    If `condition' is 0, any restart called `name' will do.
  179.    If no such restart exists, 0 is returned. */
  180. extern Tcondition_restart EXFUN
  181.   (condition_restart_find, (PTR name, Tcondition condition));
  182.  
  183. /* Return a ptrvec of the restarts that match `condition'.
  184.    If `condition' is 0, all restarts are returned. */
  185. extern Tptrvec EXFUN (condition_restarts, (Tcondition condition));
  186.  
  187. #endif /* __DSTACK_H__ */
  188.